<?php

namespace App\Console\Commands;

use App\Http\Service\Redisd;
use App\Models\StoreProduct;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class UpdateRedis extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'updateRedis';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'This is update to redis';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $data = StoreProduct::where('is_hot',1)->get()->toArray();
        Redisd::getInstance()->unlink('hot');
        foreach ($data as $k => $v){
            Redisd::getInstance()->zIncrBy('hot',$v['browse'],$v['id']);
        }
        Log::info('updateRedis success');
    }
}
